<?php
/** .-------------------------------------------------------------------
* |  Software: [HDCMS framework]
* |      Site: www.hdcms.com
* |-------------------------------------------------------------------
* |    Author: 向军 <2300071698@qq.com>
* |    WeChat: aihoudun
* | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
* '-------------------------------------------------------------------*/

namespace app\admin\controller;


class TypeAttr extends Common {
    private $db;
    public function __construct()
    {
        parent::__construct();
        $this->db=new \system\model\TypeAttr();
    }

    //动作
    public function index(){
    //此处书写代码...
        $data=Db::table('type_attr')->where('tid',Q('tid'))->paginate(5);
//        p($data);die;
        $page=$data->links();
        View::with('data',$data)->with('page',$page);
        return view();
    }
    public function add(){
        //此处书写代码...
        if(IS_POST){
//            p(Q('get.tid'));die;
            if($this->db->store()){
                message("添加成功","",'success');
            }
            message($this->db->getError(),'','error');
        }
        return view();
    }
    public function edit(){
        if(IS_POST){
//            p($_POST);die;
//             $tid= Q('post.tid');
//            p($tid);die;
            if($this->db->edit()){
                message("编辑成功",'',"success");
            }
            message($this->db->getError(),'','error');
        }

        $taid =Q('get.taid');
        $oldData = Db::table('type_attr')->where('taid',$taid)->first();
//        p($oldData);die;
        View::with('oldData',$oldData);
        return view();
    }

    public function del(){
        $taid=(int)Q('ta');
        $this->db->where('taid',$taid)->delete();
        //提示跳转
        message('删除成功','','success');
    }
}
